<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/10/16
 * Time: 17:11
 */

namespace app\flower\controller;
use cmf\controller\AdminBaseController;
use think\Db;
class AdminHomepageController extends AdminBaseController
{
     public function index(){
         $res = Db::name('flower_homepage')->find();

         if(!empty($res['images'])){
             $imgs = stripslashes($res['images']);//addslashes(json_encode($data['imgs']));
             $imgs = json_decode($imgs);

             $this->assign('images',$imgs);
         }
         return $this->fetch('index');
     }

    /**
     * 添加轮播图片
     */
    public function addImages(){
        $fileds = $this->request->param();
        $data['images'] = addslashes(json_encode($fileds['imgs']));
        $data['dottime'] = time();
        $res = Db::name('flower_homepage')->find();
        if(empty($res)){
            $result = Db::name('flower_homepage')->insert($data);
        }else{
            $result = Db::name('flower_homepage')->where('id',$res['id'])->update($data);
        }
        if($result>0){
            $this->success('提交成功');
        }else{
            $this->error('提交失败');
        }
    }
}